package com.yc.happ.serviceImpl;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.yc.happ.entity.Admin;
import com.yc.happ.entity.Elder;
import com.yc.happ.entity.Volunteer;
import com.yc.happ.service.LoginService;
import com.yc.happ.util.DBHelper;

public class LoginServiceImpl implements LoginService{

	@Override
	public Volunteer volunteerLogin(String uname,String upwd) {
		String sql1="SELECT * FROM volunteer WHERE vuname=? AND vpassword=?";
		List<Object> params=new ArrayList<Object>();
		params.add(0,uname);
		params.add(1,upwd);
		List<Map<String,String>> volunteerlist=DBHelper.doSelect(sql1, params);
		if(volunteerlist.size()>0){
			Volunteer vol=new Volunteer();
			for(Map<String,String> map:volunteerlist){
				vol.setVid(Integer.parseInt(map.get("vid")));
				vol.setVname(map.get("vname"));
				vol.setVuname(map.get("vuname"));
				vol.setVpassword(map.get("vpassword"));
				vol.setVsex(map.get("vsex"));
				vol.setVtype(map.get("vtype"));
				vol.setVaddress(map.get("vaddress"));
				vol.setVphone(map.get("vphone"));
				vol.setVspecial(map.get("vspecial"));
				vol.setVdate(map.get("vdate"));
				vol.setVtimeStart(map.get("vtimeStart"));
				vol.setVtimeEnd(map.get("vtimeEnd"));
				vol.setVscore(Integer.parseInt(map.get("vscore")));
				vol.setIsChoose(Integer.parseInt(map.get("isChoose")));
			}
			return vol;
		}
		return null;
	}

	@Override
	public Elder elderLogin(String uname,String upwd) {
		String sql2="SELECT * FROM elder WHERE vuname=? AND vpassword=?";
		List<Object> params=new ArrayList<Object>();
		params.add(0,uname);
		params.add(1,upwd);
		List<Map<String,String>> maplist=DBHelper.doSelect(sql2, params);
		if(maplist.size()>0){
			Elder elder=new Elder();
			for(Map<String,String> map:maplist){
				elder.setVid(Integer.parseInt(map.get("vid")));
				elder.setVuname(map.get("vuname"));
				elder.setIsChoose(Integer.parseInt(map.get("isChoose")));
			}
			return elder;
		}
		return null;
	}

	@Override
	public List<Admin> adminLogin(String uname, String upwd) {
		
		return null;
	}

}
